import { call, takeLatest } from 'redux-saga/effects';
import { CHANGE } from '../actions/layout.action';
import Message from '../components/SimpleLayer/Message';
import API from '../services';
 
function showErr(content){
	Message.error({
		top:'6px',
		width:'300',
		content,
		delayAutoClose:2000,
		yes:false
	});
}
function* Change(action) {
   try {
      	const res = yield call(API.Repswd, action.data);
  		if (res.success) {
  			localStorage.removeItem('e_book_user');
  			localStorage.removeItem('e_book_userinfo');
  			window.location.href='/?'+(new Date().getTime())+'#/login';
		}else{
			showErr(res.result);
		}
   } catch (e) {
      	showErr(e.message);
   }
}

function* RepswdSaga() {
  yield takeLatest(CHANGE, Change);
}

export default RepswdSaga;